﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AppCode_Admin_DeleteEmployee : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["userNameAdmin"] == null)
            {
                Response.Redirect("..\\Home\\HomePage.aspx");
            }
        }
        if (!IsPostBack)
        {
            String id = Request.QueryString["id"];
            String connect = WebConfigurationManager.ConnectionStrings["ConnectDatabase"].ToString();
            SqlConnection sqlConnect = new SqlConnection(connect);
            sqlConnect.Open();
            SqlCommand sqlCommand = new SqlCommand("Select *from EmpRegister where Empno=" + id, sqlConnect);
            SqlDataReader reader = sqlCommand.ExecuteReader();
            reader.Read();
            txtDesignation.Text = reader.GetString(1);
            txtJoinDate.Text = reader.GetDateTime(2).ToString();
            txtSalary.Text = reader.GetDecimal(3).ToString();
            txtFirstName.Text = reader.GetString(4);
            txtLastName.Text = reader.GetString(5);
            txtUserName.Text = reader.GetString(6);
            txtAddress.Text = reader.GetString(8);
            txtContact.Text = reader.GetString(9);
            txtState.Text = reader.GetString(10);
            txtCountry.Text = reader.GetString(11);
            txtCity.Text = reader.GetString(12);
            sqlConnect.Close();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String id = Request.QueryString["id"];
        String connect = WebConfigurationManager.ConnectionStrings["ConnectDatabase"].ToString();
        SqlConnection sqlConnect = new SqlConnection(connect);
        sqlConnect.Open();
        SqlCommand sqlCommand = new SqlCommand("Delete From EmpRegister where Empno=" + Request.QueryString["id"], sqlConnect);
        sqlCommand.ExecuteNonQuery();
        sqlConnect.Close();
        Response.Redirect("EmployeeDetails.aspx");
    }
}